﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApplication1.Class.Bean;

namespace WpfApplication1
{
    /// <summary>
    /// Logique d'interaction pour Window1.xaml
    /// </summary>
    public partial class FilterWindow : Window
    {
        private ListView list;

        public FilterWindow(ListView list)
        {
            InitializeComponent();

            this.list = list;

            this.prioriteBox.Items.Add(ClassBug.PRIORITE_BASSE);
            this.prioriteBox.Items.Add(ClassBug.PRIORITE_MOY);
            this.prioriteBox.Items.Add(ClassBug.PRIORITE_HAUTE);

            this.etatBox.Items.Add(ClassBug.ETAT_OUVERT);
            this.etatBox.Items.Add(ClassBug.ETAT_ATTENTE);
            this.etatBox.Items.Add(ClassBug.ETAT_FERME);

            this.typeBox.Items.Add(ClassBug.TYPE_DEMANDE_CORRECTION);
            this.typeBox.Items.Add(ClassBug.TYPE_DEMANDE_EVOLUTION);
            this.typeBox.Items.Add(ClassBug.TYPE_DEVELOPPEMENT);

        }

        private void ValidFilter(object sender, RoutedEventArgs e)
        {

            List<ClassBug> listPrio = new List<ClassBug>();
            List<ClassBug> listEtat = new List<ClassBug>();
            List<ClassBug> listType = new List<ClassBug>();

            if(this.prioriteBox.SelectedItem != null || this.etatBox.SelectedItem != null|| this.typeBox.SelectedItem != null)
            {

  

                    List<SearchField> listSF = new List<SearchField>();

                    if(this.prioriteBox.SelectedItem != null)
                        listSF.Add(new SearchField("Priorite", this.prioriteBox.SelectedItem.ToString(), SearchField.EGAL_A));
                    if (this.etatBox.SelectedItem != null)
                        listSF.Add(new SearchField("Etat", this.etatBox.SelectedItem.ToString(), SearchField.EGAL_A));
                    if (this.typeBox.SelectedItem != null)
                        listSF.Add(new SearchField("Type", this.typeBox.SelectedItem.ToString(), SearchField.EGAL_A));

                    List<ClassBug> listFinal = ClassBug.Search(listSF);
                

               
                if (listFinal.Count == 0)
                    MessageBox.Show("Aucun bug ne correspond à la selection");
                else
                {
                    Binding bind = new Binding();
                    bind.Source = listFinal;
                    this.list.DisplayMemberPath = "Nom";
                    this.list.SetBinding(DataContextProperty, bind);

                    this.Close();
                }
            }
            else
                MessageBox.Show("Selectionner au moins un filtre");
        }
    }
}
